<?php

use yii\db\Migration;

class m180313_072933_create_report_record extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%report_record}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'module_id' => $this->integer()->defaultValue(0)->comment('模块id'),
                'sender_id' => $this->integer()->defaultValue(0)->comment('提报者id'),
                'sendee_id' => $this->integer()->defaultValue(0)->comment('接收者id'),
                'stage' => $this->smallInteger(4)->defaultValue(0)->comment('环节id'),
                'type' => $this->smallInteger(2)->defaultValue(0)->comment('类型id（1 商品 2 结算）'),
                'status' => $this->smallInteger(2)->defaultValue(0)->comment('0 未查看 1 通过 2 未通过'),
                'mechanicremark' => $this->string(255)->defaultValue(null)->comment('机构备注'),
                'workerremark' => $this->string(255)->defaultValue(null)->comment('广场工作人员'),
                'is_visual' => $this->smallInteger(1)->defaultValue(1)->comment('机构是否可见广场工作人员的备注'),
                'operator_type' => $this->string(50)->defaultValue(null)->comment('提交人类型(square 广场人员 mechanic 机构人员 '),
                'updated_at' => $this->integer()->defaultValue(0)->comment('修改时间'),
                'created_at' => $this->integer()->defaultValue(0)->comment('创建时间')
            ]);
        }

    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%report_record}}');
        }
    }
}
